import java.util.LinkedList;


class P11489_39643 {

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString());
	}

	public static void main(String[] args) {

		int cases = Integer.parseInt(readLn());

		for (int k = 0; k < cases; k++) {
			String line = readLn();

			LinkedList<Integer> array = new LinkedList<Integer>();

			for (int i = 0; i < line.length(); i++) {
				array.add(Integer.parseInt(line.charAt(i) + ""));
			}
			System.out.print("Case " + (k + 1) + ": ");
			if (array.size() == 1) System.out.println("S");
			else if (!canFirstRemove(array)){
				System.out.println("T");
			} else {
				removeFirst(array);
				if (array.size() == 1) System.out.println("T");
				else {
					int count = 0;
					
					for (int i : array)
						if (i == 3 || i == 6 || i == 9) count++;
					
					if (count % 2 == 0) System.out.println("S");
					else System.out.println("T");
				}
			}
		}

	}


	
	private static void removeFirst(LinkedList<Integer> array) {
		int sum = 0;

		for (int k = 0; k < array.size(); k++) {
			sum += array.get(k);
		}

		for (int k = 0; k < array.size(); k++) {
			if ((sum - array.get(k)) % 3 == 0) {
				array.remove(k);
				return;

			}
		}

	}
	
	private static boolean canFirstRemove(LinkedList<Integer> array) {
		int sum = 0;

		for (int k = 0; k < array.size(); k++) {
			sum += array.get(k);
		}

		for (int k = 0; k < array.size(); k++) {
			if ((sum - array.get(k)) % 3 == 0) {
//				 System.out.println(array[k]);
//				array.remove(k);
				return true;

			}
		}

		return false;
	}

}
